<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Image Manager</title>
<link type="text/css" rel="stylesheet" href="<?=admin_css('j_pagination.css')?>" />
<script type="text/javascript" src="<?=admin_js("jquery-1.4.3.min.js")?>"></script>
<?php
$uri    = $this->uri->uri_to_assoc(4);
$uri_2  = $uri; unset($uri_2['dir']);
?>
<script type="text/javascript">
            $(function ()
            {
                $('[class*=remove_]').click(function ()
                {
                        var i_class = $(this).attr('class');
                        $.ajax({
                                type: "POST",
                                url: "<?=base_url_admin('image/delete')?>",
                                data: "src=" + $(this).attr('src'),
                                success: function(success) {
                                        if(success) {
                                                $('#'+i_class).fadeOut();
                                        }
                                }
                        });
                        return false;
                });

                //On Click Event
                $("ul.tabs li").click(function() {
                    $("ul.tabs li").removeClass("active"); //Remove any "active" class
                    $(this).addClass("active"); //Add "active" class to selected tab
                    $(".tab_content").hide(); //Hide all tab content
                    var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
                    $(activeTab).fadeIn(); //Fade in the active content
                    return false;
                });
            });

            function togleUpload()
            {
                $("#UploadImages").toggle('medium',function () {
                    if($("#toggleText").html()=='Close upload form'){
                        $("#toggleText").html('Show upload form');
                    }else {
                        $("#toggleText").html('Close upload form');
                    }
                });
            }

            function add_to(src)
            {
                <?php if(isset($uri['position'])): ?>
                <?php if($uri['position'] == 'thumb'): ?>
                    window.opener.$("#image_thumb").attr('src', src);
                    window.opener.$("#image").val(src);
                <?php else: ?>
                    window.opener.$("#"+window.opener.ADMIN_IMAGE_INPUT_TEXT).val(src);
                <?php endif; ?>
                <?php endif; ?>
                window.close();
            }

            function show_tooltips(src)
			{    		    		
            	$("#views_img_root").attr('src', src)
			} 		

           function delete_img(url)
           {
                if(!confirm('Do you want delete this item ?'))
                {
                     return;
                }
                var data ={};
                data['url_img'] = url;
                data['src'] = url;
                $.ajax({
	        url: '<?php echo base_url_admin('image/delete_img/');?>',
	        type: 'POST',
                data:data,
	        error: function(){
	            alert('Error !');
	        },
	        success: function(success)
	        {                    
                    alert("Delete success!");
                    location.reload();
	        }
	    });

           }
</script>

	</head>
	<body>

        <?=$this->message->display()?>

        <div style="display: none;" id="UploadImages">
            <ul class="tabs">
                <li class="active"><a href="#tab1">Upload</a></li>
                <li><a href="#tab2">Create Folder</a></li>
            </ul>

            <div class="tab_container">
                <div class="tab_content" id="tab1">
                    <form enctype="multipart/form-data" style="padding-top: 10px;" name="add_image" id="add_image" action="<?=base_url_admin('image/upload/'.$this->uri->assoc_to_uri($uri))?>" method="post">
                    <div id="photo-add">
                    <div>
                        <b>Upload options</b>:
                        <div style="margin-left: 40px;">
                        <div style="line-height: 30px;">
                        Upload to: <select style="width: 300px; padding: 2px; margin-left: 40px;" name="uploadTo" id="uploadTo">
                        <option value="">Select folder...</option>
                        <?php if($list_folder): ?>
    				    <?php foreach($list_folder as $f): ?>
    				      <?php if($f<2010): ?>
                          <option value="<?php echo $f;?>"><?php echo $f;?></option>
                           <?php endif; ?>
                        <?php endforeach; ?>
                        <?php endif; ?>
                        </select>
                        </div>
                        <div style="line-height: 30px;">
                        Thumb Priority: <select style="width: 300px; padding: 2px; margin-left: 11px;" name="thumbOption">
                        <option>Select demension priority...</option>
                        <option style="color: green; margin-left: 20px;" value="width">Width</option>
                        <option style="color: green; margin-left: 20px;" value="height">Height</option>
                        </select>
                        </div>
                        </div>
                    </div>

                    <div>
                        <b>Select file to upload</b>:
                        <div style="margin-left: 40px;">
                        <div id="images_wrap" class="MultiFile-wrap">
                        <input type="file" accept="gif|jpg|jpeg|png" id="images" name="art_image" maxlength="10" class="multi MultiFile-applied" />
                        </div><br />
                        <input type="submit" value="Upload images" />
                        </div>
                    </div>
                    </div>
                    </form>
                </div>
                <div id="tab2" class="tab_content" style="display: none;">
                    <form method="post" action="<?=base_url_admin('image/create_dir/'.(isset($uri['dir']) ? 'dir/'.$uri['dir'] : ''))?>" id="create_dir" name="create_dir" style="padding-top: 10px" enctype="multipart/form-data">

                    <div style="font-size: 13px; font-weight: normal;">
                    <b>Folder's name</b>: <input type="text" name="dir_name" id="dir_name"/>
                    <input type="submit"  value="Create folder" />
                    </div>

                    </form>
                </div>
            </div>
        </div>

		<div id="wrapper">

            <div style="width: 98%; padding-left: 10px; margin-top: 10px;" class="breadCrumb">
            <div style="float: left; width: 300px;">
            <ul>
                <li><a href="<?=creat_uri($uri_2)?>">Root</a></li>

                <?php
                $defalt_thumb = "thumb_".end(thumbs());
				$tt         = count($root);

				foreach($root as $i => $sub) {
                    echo '<li><a href="'.creat_uri($uri_2, $sub).'">'.$sub.'</a></li>';

                    if(isset($uri_2['dir']) && $uri_2['dir'] != '') $uri_2['dir'] .= ':'.$sub;
                    else $uri_2['dir'] = $sub;
				}
				?>
            </ul>
            </div>
            <span onclick="togleUpload();" style="float: right; cursor: pointer; color: blue; margin-top: 5px; margin-right: 15px;" id="toggleText">Show upload form</span>
            </div>

			<div id="paging_container" class="container">			
                <div style="float: left; width: 60%; margin-left: 10px; margin-bottom: 10px;margin-top: 10px;margin-right: 2px;" id="imagesThumb">
                <?php if($map): ?>
    				<?php foreach($map as $item): ?>

    					<?php if(preg_match('@\.(png|jpg|gif)@is', $item)): ?>

                        <div style="float: left; width: 80px; margin: 10px;" id="imagesThumb">
                            <img id="imgs_thump" width="87" src="<?=creat_path($uri, $defalt_thumb.'/'.$item)?>" style="border: 3px solid rgb(204, 204, 204); cursor: pointer; float: left; margin-right: 5px; margin-top: 5px;" onclick="add_to('<?=creat_path($uri,  $defalt_thumb."/".$item)?>');"  class="imagesContextAction" onmouseover="show_tooltips('<?php echo creat_path($uri,  $item);?>');"/>
                            <img width="20" src="<?php echo admin_img('cross_circle.png')?>" style="cursor: pointer; float: left; margin-right: 5px; margin-top: 5px;" onclick="delete_img('<?=create_dirx($uri,  $defalt_thumb."/".$item)?>');"  class="imagesContextAction" />
                        </div>

    					<?php elseif(!preg_match('@(thumb\_|\.flv|\.mp4)@is', $item)): ?>

    					<div style="width: 188px; float: left; margin-bottom: 10px;"><a href="<?=creat_uri($uri, $item)?>"><?=$item?></a></div>&nbsp;&nbsp;

    					<?php endif; ?>

    				<?php endforeach; ?>
                <?php endif; ?>
                </div>
				
				<div style="float: right; width: 30%; margin-right: 30px;margin-top:50px;" id="imagesThumb_view">
					<img src="<?php echo admin_img('no_image.gif');?>" id="views_img_root" style="width:300px;height:450px;border:1px solid #59E817;"/>
				</div>
				<div style="margin:50px 0; clear:both"></div>
			</div>			
		</div>
	</body>
</html>
